package jamirr;

import java.util.Map;

public interface ReturnType<T> extends TypeInformation<T> {

    default Argument<T> asArgument() {
        return Argument.of(getType());
    }

    /**
     * Create a new return type from the given type and arguments.
     *
     * @param type          The type
     * @param typeArguments The type arguments
     * @param <T1>          The return type
     * @return A {@link ReturnType}
     */
    static <T1> ReturnType<T1> of(Class<T1> type, Argument<?>... typeArguments) {
        Map<String, Argument<?>> argumentMap = Utils.newLinkedHashMap(typeArguments.length);
        for (Argument<?> argument : typeArguments) {
            argumentMap.put(argument.getName(), argument);
        }
        return new ReturnType<>() {

            @Override
            public Class<T1> getType() {
                return type;
            }

            @SuppressWarnings("rawtypes")
            @Override
            public Argument[] getTypeParameters() {
                return typeArguments;
            }

            @Override
            public Map<String, Argument<?>> getTypeVariables() {
                return argumentMap;
            }
        };
    }
}
